package com.leet.competition;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class CountPalindromic {
    public int countPalindromicSubsequence(String s) {
        HashSet<String> visited = new HashSet<>();
        for(int i = 0 ; i < 26; i++){
            // 取第一个
            char head = (char) (i +'a');
            int begin = s.indexOf(String.valueOf(head));
            int end = s.lastIndexOf(String.valueOf(head));
            // 循环遍历
            if (begin < end){
                for(int j = begin+1; j < end; j++){
                    visited.add(new String(new char[]{head,s.charAt(j),head}));
                }
            }
        }
        return visited.size();
    }
}
